package app

import (
	"gitee.com/leaf-rain-gitee/util/gin_tool/pkg/convert"
	"github.com/gin-gonic/gin"
)

func GetPage(c *gin.Context) int64 {
	page := convert.StrTo(c.Query("page")).MustInt64()
	if page <= 0 {
		return 1
	}

	return page
}

func GetPageSize(c *gin.Context) int64 {
	pageSize := convert.StrTo(c.Query("page_size")).MustInt64()
	//if pageSize <= 0 {
	//	return global.AppSetting.DefaultPageSize
	//}
	//if pageSize > global.AppSetting.MaxPageSize {
	//	return global.AppSetting.MaxPageSize
	//}
	return pageSize
}

func GetPageOffset(page, pageSize int64) int64 {
	var result int64 = 0
	if page > 0 {
		result = (page - 1) * pageSize
	}

	return result
}
